<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise封装setInterval定时器</title>
</head>
<body>
    <script>
        function interval(delay = 1000,callback){
            return new Promise(resolve => {
                let id = setInterval(() => {
                    callback(id,resolve)
                }, delay);
            });
        }

        interval(2000,(id,resolve) => {
            console.log("xiasnn");
            clearInterval(id);
            resolve();
        }).then(
            value =>{
                console.log("成功");
            }
        )
    </script>
</body>
</html>